package com.deluxelx.soul.inn.common.util;

import java.time.LocalDateTime;
import java.util.Random;

/**
 * 处理一些数字的工具类
 *      1. 1200 变成 1.2k 这种
 *      2. 咨询师 level 计算
 *
 * @author: zihao.liao
 * @date: 2024/5/5 19:17
 */
public class SpecialNumUtil {

    public static String getFollowTypeNum(int num) {
        String chatCountStr;
        chatCountStr = num + "";
        if (num > 100 && num < 1000) {
            int remainder = num % 100;
            num -= remainder;
            chatCountStr = num + "";
        }
        if (num >= 1000 && num < 10000) {
            double chatCountD = Math.floor(((double) num / 1000) * 10) / 10;
            chatCountStr = chatCountD + "k";
        }
        if (num >= 10000) {
            double chatCountD = Math.floor(((double) num / 10000) * 10) / 10;
            chatCountStr = chatCountD + "w";
        }
        return chatCountStr;
    }

    public static int getCounselorLevel(int chatCount, long year) {
        int level = 1;
        if (chatCount > 300 && year >= 3) {
            level = 2;
        }
        if (chatCount > 2000 && year >= 6) {
            level = 3;
        }
        return level;
    }

    public static String getConsultNum(LocalDateTime dateTime) {
        String metaData = DateTimeUtil.getAppointmentCreateTime(dateTime);
        String[] arr = metaData.split(" ");
        String str1 = arr[0].replace("-", "");
        String str2 = new StringBuilder(arr[1].replace(":", "")).reverse().toString();
        String str3 = dateTime.getHour() < 12 ? "QQ" : "ZH";
        return str1 + str2 + str3 + generateRandomString(4);
    }

    private static String generateRandomString(int length) {
        String characters = "A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8S9T0U1V2W3X4Y5Z";
        StringBuilder sb = new StringBuilder();
        int strLen = characters.length();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(strLen);
            sb.append(characters.charAt(index));
        }
        return sb.toString();
    }
}
